<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

class PermissionController extends BaseController
{
    protected $api_url = [
        'index' => ['get', 'permission'],
        'show' => ['get', 'permission/%d'],
        'store' => ['post', 'permission'],
        'update' => ['put', 'permission/%d'],
        'destroy' => ['delete', 'permission/%d']
    ];

    public function index(Request $request)
    {
        $res = http_admin($this->api_url['index'])->send(['page' => $request->input('page', 1)]);
        $data = paginate($request, $res['data']);

        return view('Admin.permission.index', $data);
    }

    public function edit($id)
    {
        $res = http_admin($this->api_url['show'], [$id])->send();
        return view('Admin.permission.edit', $res['data']);
    }

    public function create()
    {
        return view('Admin.permission.create');
    }

    public function store(Request $request)
    {
        $data = $request->except('_token', '_method');
        $res = http_admin($this->api_url['store'])->send($data);
        return redirect('/foradmin/permission');
    }

    public function update($id, Request $request)
    {
        $data = $request->except('_token', '_method');
        $res = http_admin($this->api_url['update'], [$id])->send($data);
        return redirect('/foradmin/permission');

    }

    public function destroy($id)
    {
        $res = http_admin($this->api_url['destroy'], [$id])->send();
        return redirect('/foradmin/permission');
    }
}
